/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 比赛.全国大学生程序设计大赛.A2021_未参赛;

import java.util.Scanner;

public class Three {
    private static int x=0,y=0,z=0;
    public static void main(String arg[]){//main--来自高金磊
        Scanner scanner = new Scanner(System.in);
        int N=scanner.nextInt();
        int L=scanner.nextInt();
        x = scanner.nextInt();
        y = scanner.nextInt();
        z = scanner.nextInt();
        //构造前缀和
        int[] data=new int[N+2];
        for (int i = 1; i < data.length - 1; i++) {
            data[i]=data[i-1]+plus(i);
        }
        data[data.length-1]=data[data.length-2];

        //滑动窗口
        int max=0;
        for (int i = 0; i < data.length - L; i++) {
            max=Math.max(max, data[i+L]-data[i]);
        }
        System.out.println(max);


    }

    private static int plus(int i) {
        if (i%x==0&&i%y==0&&i%z==0){
            return 10;
        }
        if (i%x==0&&i%z==0){
            return 8;
        }
        if (i%y==0&&i%z==0){
            return 4;
        }
        if (i%x==0&&i%y==0){
            return 2;
        }
        return 1;

    }

}
